package com.test.design_pattern.singleton;

/**
 * 静态内部类方式
 * JVM保证单例
 * 加载外部类时不会加载内部类，这样可以实现懒加载
 */
public class Single01 {
    private Single01(){
    }

    private static class Single01Holder{
        private final static Single01 INSTANCE = new Single01();
    }

    public static Single01 getInstance(){
        return Single01Holder.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i=0;i<100;i++){
            new Thread(()->{
                System.out.println(Single01.getInstance().hashCode());
            }).start();
        }
    }
}